﻿Ext.define('app.system.user.Import',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    width: 400,
    height: 200,
    title: '导入用户',
    layout: 'fit',
    bodyStyle: 'padding:50px 0 0 0',
    initComponent: function () {
        var me = this;
        me.items = [me.getForm()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSubmit },
            { text: '关闭', handler: function () { me.close(); } }
        ];
        me.callParent();
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.Panel({
                border: false,
                defaults: { anchor: '100%' },
                defaults: {
                    anchor: '100%'
                },
                fieldDefaults: {
                    labelWidth: 70,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    {
                        xtype: 'filefield',
                        name: 'importFile'
                    },
                    {
                        xtype: 'displayfield',
                        value: '<a href="/api/services/app/user/GetUserImportTpl">下载模板</a>'
                    }
                ]
            });
        }
        return this.form;
    },
    onSubmit: function () {
        var me = this;
        var fileValue = me.form.query("filefield[name=importFile]")[0].getValue();
        if (fileValue == "") {
            Ext.Msg.alert("系统提示!", "请选择文件");
            return false;
        }
        me.form.getForm().submit(
        {
            url: '/api/services/app/user/ImportUser',
            waitMsg: '正在提交数据',
            waitTitle: '提示',
            method: "POST",
            success: function (form, action) {
                var obj = Ext.util.JSON.decode(action.response.responseText);
                Ext.Msg.alert("系统提示!", "导入成功");
                me.fireEvent("savesuccess");
            }
        });
    }
});